package com.yhj.reggie.controller;

import com.yhj.reggie.common.R;
import com.yhj.reggie.dto.OrdersDto;
import com.yhj.reggie.entity.Orders;
import com.yhj.reggie.entity.Page;
import com.yhj.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/submit")
    public R<String> submit(@RequestBody Orders orders, HttpSession session){
        Long userId =(Long)session.getAttribute("user");

        orderService.addOrder(orders,userId);

        return R.success("下单成功");
    }

    @GetMapping("/userPage")
    public R<Page<OrdersDto>> findAllOrders(@RequestParam Integer page,@RequestParam Integer pageSize, HttpSession session){
        Long userId =(Long)session.getAttribute("user");
        Page<OrdersDto> rePage = orderService.findByUser(page, pageSize, userId);
        return R.success(rePage);
    }
}
